package com.fzb.forum4j.service.impl;

import javax.annotation.Resource;

import org.springframework.stereotype.Service;

import com.fzb.forum4j.dao.api.IBlogDao;
import com.fzb.forum4j.dao.api.IBlogSortDao;
import com.fzb.forum4j.dao.api.IUserDao;
import com.fzb.forum4j.po.Blog;
import com.fzb.forum4j.po.QueryMode;
import com.fzb.forum4j.service.api.IBlogService;
import com.fzb.forum4j.service.api.ICommentService;
@Service("blogServiceImpl")
public class BlogServiceImpl extends BaseServiceImpl<Blog> implements
		IBlogService {

	@Resource(name="blogDaoImpl")
	private IBlogDao blogDao;
	
	@Resource(name="userDaoImpl")
	private IUserDao userDao;
	
	@Resource(name="blogSortDaoImpl")
	private IBlogSortDao blogSortDao;
	
	@Resource(name="commentServiceImpl")
	private ICommentService commentService;
	@Override
	public void getBlogAndComment(QueryMode<Blog> qmd) {
		blogDao.getEntityByEid(qmd);
		commentService.getBlogCommentsByCid(qmd);
		qmd.getData().put("user", userDao.getSimpleDataByUserName(qmd.getT().getUser().getUserName()));
		blogSortDao.getBlogSortByUserName(qmd);
	}
	

	
	@Override
	public void getBlogsByUser(QueryMode<Blog> qmd) {
		blogDao.getBlogsByUser(qmd);
	}
	@Override
	public void getBlogsBySort(QueryMode<Blog> qmd) {
		blogDao.getBlogsBySort(qmd);
	}
	@Override
	public void getList(QueryMode<Blog> qmd) {
		blogDao.getList(qmd);
		if(qmd.getT().getUser()!=null){
			qmd.getData().put("user", userDao.getSimpleDataByUserName(qmd.getT().getUser().getUserName()));
		}
	}
	@Override
	public void getBlogRecommend(QueryMode<Blog> qmd) {
		blogDao.getBlogRecommend(qmd);
	}



	@Override
	public void getBlogSortByUserName(QueryMode<Blog> qmd) {
		blogSortDao.getBlogSortByUserName(qmd);
	}



	@Override
	public void getBlogsByQmd(QueryMode<Blog> qmd) {
		if(qmd.getKeyword()!=null){
			qmd.getT().setKeywords("%"+qmd.getKeyword()+"%");
			blogDao.getBlogsByQmd(qmd);
		}
	}



	@Override
	public void getSimpleBlogMsgByUserAndCid(QueryMode<Blog> qmd) {
		blogDao.getSimpleBlogMsgByUserAndCid(qmd);
	}

}
